package ocg.common.re.influx.Influx;

import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;

/**
 * Created by chenbo on 2018/2/11.
 */
public class InfluxdbBuilder {

    private String   username;
    private String   password;
    private String   url;

    private InfluxDB influxDB;

    public InfluxdbBuilder(String username, String password, String url) {
        this.username = username;
        this.password = password;
        this.url = url;
    }

    /**
     * 创建 influxDB 链接
     * @return
     */
    public InfluxDB build() {
        if (influxDB == null) {
            synchronized (this) {
                if (influxDB == null) {
                    influxDB = InfluxDBFactory.connect( url, username, password );
                }
            }
        }
        return influxDB;
    }

}
